{extend name="common/application" /}
{block name="title"}<title id="title">店铺中心-我的店铺</title>{/block}
{block name="css"}
<link rel="stylesheet" type="text/css" href="_CSS_/reset.css">
<link rel="stylesheet" type="text/css" href="_CSS_/common.css">
<link rel="stylesheet" type="text/css" href="_CSS_/store.css"/>
<!--[if lt IE 9]>
<script src="http://www.ijquery.cn/js/html5shiv.js"></script>
<![endif]-->
<style>
    .sp1 {
        width: 34px;
        height: 16px;
        background-color: #17c6ac;
        color: #ffffff;
        font-size: 12px;
        line-height: 16px;
        text-align: center;
        margin-right: 10px;
    }

    .serviceHeader {
        margin-top: 10px
    }
	
	.publist-box{min-height:976px;}
	
    .nodatas {
        text-align: center;
    }

    .nodatas img {
        display: inline-block;
        margin-top: 200px;
        margin-bottom: 20px;
    }

    .items {
        border: 1px solid #e5e5e5;
    }

    .links img {
        width: 168px;
        height: 168px;
    }

    .borderLine {
        border: 0;
    }
</style>
{/block}

{block name="content"}
<!-- 主体内容 -->
<div class="main">
    <div class="mainBody normalBox clearfix" style="padding-top: 14px;">
        <!--店铺信息-->
        <div class="storeArea fl">
            <div class="basicInfo">
                <a class="storeLogo userImg" href="javascript:;">
                    <img src="/static/web/images/76.png" class="icon-wapper hide">
                    <img id="image" src="/static/web/images/store.jpg" class="icon">
                </a>
                <h4 class="storeName name text_overflow" title=""></h4>
                <p>卖家：<span class="sellerman name"></span></p>
                <br/>
                <span class="icons sp1 name"></span>
                <span class="icons icon-ensure"></span>
            </div>
            <p>成交量<span class="name"></span>次</p>
            <p>本店铺一共<span class="name"></span>件商品，其中交易类商品<span class="name"></span>件，服务类商品<span class="name"></span>件。
            </p>
            <p class="name">
            </p>
            <!--<p>主营：专利转让、商标版权与专利转让专利转让、商标版权与专利转让专利转让、商标版权与专利转让专利转让、商标版权与专利转让</p>-->
        </div>
        <!--店铺商品列表-->
        <div class="productList fr">
            <div class="productsListHeader">
                <a class="productType on" href="javascript:;">交易类商品</a>
                <a class="productType" href="javascript:;">服务类商品</a>
            </div>
            <input type="hidden" id="value">
            <input type="hidden" id="index">
            <div class="serviceHeader">
                <div class="serviceNavi fl">
                    <a class="sortType active" value="0" href="javascript:;">综合排序</a>
                    <a class="sortType" value="1" href="javascript:;">授权量</a>
                    <a class="sortType" value="2" href="javascript:;">评价量</a>
                    <a class="sortType" value="3" href="javascript:;">时间</a>
                </div>
                <div class="priceRange fl">
                    <a class="showDiv fl" href="javascript:;">价格<span class="icons icon-arrowdown"></span></a>
                    <input class="minPrice" type="number" placeholder="￥"/>
                    <span class="fl">-</span>
                    <input class="maxPrice" type="number" placeholder="￥"/>
                    <div class="hideBox sortBox">
                        <a class="asc cur" href="javascript:;">按价格从低到高</a>
                        <a class="desc" href="javascript:;">按价格从高到低</a>
                    </div>
                    <a class="sendButton" href="javascript:;">确定</a>
                </div>
                <div class="total fr">
                    <p class="mr20">共<span class="num" id="count"></span>件商品</p>
                    <a class="prev" href="javascript:;">
                        <span class="icons icon-prev hide"></span>
                        <span class="icons icon-grey-prev"></span>
                    </a>
                    <p><span class="currentPage">1</span>/<span class="allPage"></span></p>
                    <a class="next" href="javascript:;">
                        <span class="icons icon-next"></span>
                        <span class="icons icon-grey-next hide"></span>
                    </a>
                </div>
            </div>
            <div class="publist-box">
                <div class="serviceArea">
                </div>
            </div>

            <div class="publist-box hide">
                <div class="serviceArea">
                </div>
            </div>
            <div class="page"></div>
            <div class="page"></div>
        </div>
        <!--推荐区-->
        <div class="recommendAreas fl">
            <div class="recommendArea services">
                <div class="recommendHeader">
                    <span class="fl">推荐交易</span>
                    <a class="refreshBtn fr" href="javascript:;"><span class="icons icon-refresh"></span></a>
                </div>
                <div class="recommendCon">

                </div>
            </div>
            <div class="recommendArea trades mt20">
                <div class="recommendHeader">
                    <span class="fl">推荐服务</span>
                    <a class="refreshBtn fr" href="javascript:;"><span
                            class="icons icon-refresh"></span></a>
                </div>
                <div class="recommendCon">
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<!-- 脚本引入 -->
<script src="_P_/layer/layer.js"></script>
<script src="_JS_/trading.js"></script>
<script>
    $(function () {
        hot_view();
        get_view();
        postfile(1, '交易类商品');
    });


    /*交易市场与服务市场*/
    $('.productsListHeader a').on('click', function () {
        $('.productsListHeader a').removeClass('on');
        $(this).addClass('on');
        var num = $(".productsListHeader a").index(this);
        $(".publist-box").hide();
        $(".publist-box").eq(num).show();
        var text = $(this).text();
        $("#index").val(text);
        if (text == '服务类商品') {
            $(".page").eq(0).hide();
            $(".page").eq(1).show();
            $("#value").val("");
            $('.maxPrice').val("");
            $('.minPrice').val("");

        } else {
            $(".page").eq(1).hide();
            $(".page").eq(0).show();
            $("#value").val("");
            $('.maxPrice').val("");
            $('.minPrice').val("");
        }
        postfile(1, text);
    });

    $('.prev').on('click', function () {
        var prev_num = parseInt($('.currentPage').html()) - 1;
        var index = $("#index").val();
        var value = $("#value").val();
        if (prev_num != 0) {
            postfile(prev_num, index, value);
        }
    });
    $('.next').on('click', function () {
        var value = $("#value").val();
        var next_num = parseInt($('.currentPage').html()) + 1;
        var max_num = parseInt($('.allPage').html());
        var index = $("#index").val();
        if (next_num <= max_num) {
            postfile(next_num, index, value);
        }
    });

    $(".sortType").on('click', function () {
        var value = $(this).attr('value');
        var index = $("#index").val();
        $("#value").val(value);
        postfile(1, index, value);
    });
    $(".asc").click(function () {
        var index = $("#index").val();
        $("#value").val(4);
        postfile(1, index, 4);
    });
    $(".desc").click(function () {
        var index = $("#index").val();
        $("#value").val(5);
        postfile(1, index, 5);
    });

    $(".sendButton").on('click', function () {
        var index = $("#index").val();
        var value = $("#value").val();
        postfile(1, index, value);
    });

    function postfile(page, text, value) {
        var userinfo = $.cookie('userinfo');
        if (userinfo != null) {
            var user_login = $.base64.decode(userinfo).split(",");
            if (text == '服务类商品') {
                var index = 2;
            } else {
                var index = 1;
            }
            var minmoney = $('.minPrice').val();
            var maxmoney = $('.maxPrice').val();
            $.ajax({
                type: "get",
                url: "{:url('api/shop/center')}",
                data: {
                    'page': page,
                    'uid': user_login[0],
                    'index': index,
                    'value': value,
                    'minmoney': minmoney,
                    'maxmoney': maxmoney
                },
                dataType: 'jsonp',
                success: function (msg) {
                    if (msg.code == 200) {
						if(msg.data.image == null){
							$("#image").attr('src', '/static/web/images/store.jpg');
						}else{
							$("#image").attr('src', '/Images/Information/' + msg.data.image);
						}
                        $(".name").eq(0).html(msg.data.name);
                        $(".name").eq(0).attr('title', msg.data.name);
                        $(".name").eq(1).html(msg.data.username);
                        $(".name").eq(2).html(msg.data.shop_name);
                        $(".name").eq(3).html(msg.data.shop_volume);
                        $(".name").eq(4).html(msg.data.trading_count + msg.data.service_count);
                        $(".name").eq(5).html(msg.data.trading_count);
                        $(".name").eq(6).html(msg.data.service_count);
                        $(".name").eq(7).html("");
                        if (msg.data.label_shop.length > 0) {
                            for (var i = 0; i < msg.data.label_shop.length; i++) {
                                if ($.inArray(msg.data.label_shop[i].id + '', msg.data.label) != -1) {
                                    $(".name").eq(7).append('<span class="labels">' + msg.data.label_shop[i].name + '</span>');
                                }
                            }
                        }

                        if (index == 1) {
							$('.sortType').eq(2).attr('style','display:none;');
                            $('.num').html(msg.data.count);
                            $('.currentPage').html(page);
                            var pages = Math.ceil(msg.data.count / 20);
                            $('.allPage').html(pages);
                            $(".count").html(msg.data.count);
                            var re = /^[0-9]+$/;
                            var market = "";//商品
                            //商品
                            if (msg.data.trading.length != 0) {
                                for (var j = 0; j < msg.data.trading.length; j++) {
									var storeName = cut(msg.data.trading[j].username,18);
                                    var price_num = number_format(msg.data.trading[j].store, 2, ".", ",");
                                    if (re.test((j + 1) / 5)) {
                                        market += '<div class="serviceItem mr0">';
                                    } else {
                                        market += '<div class="serviceItem">';
                                    }
                                    market += '<a class="goDetails" href="/index.php/index' +
                                        '/trade/trade_details.html?id=' + msg.data.trading[j].id + '">' +
                                        '<img src="/Images/tradingMarket/' + msg.data.trading[j].image + '"></a><div class="serviceCon">' +
                                        '<span class="prices">￥' + price_num + '</span>' +
                                        '<a class="serviceTitle moreline" limit="20" href="/index.php/index' +
                                        '/trade/trade_details.html?id=' + msg.data.trading[j].id + '">' + storeName + '</a>' +
                                        '<a class="company text_overflow" href="store_details.html" title="">' + msg.data.trading[j].name + '</a>' +
                                        '<p class="volume">授权量<span class="volumeNum">' + msg.data.trading[j].value + '</span>笔</p>' +
                                        '</div></div>';
                                }
                                $(".serviceArea").eq(0).html(market);
                                if (msg.data.trading.length == 0) {
                                    $('.page').eq(0).html('');
                                } else {
                                    $('.page').eq(0).html(msg.data.render);
                                    $(".pagination").eq(0).delegate("a", "click", function () {
                                        var index = $("#index").val();
                                        var num = $(this).attr("num");
                                        var value = $("#value").val();
										
                                        if (num) {
                                            postfile(num, index, value);
                                        }
                                    });
									$("#GO").on('click',function(){
										var king = $("#go").val();
										if(king > pages){
											layer.alert("最多输入"+pages+"页");
											return;
										}
										postfile(king, c_id, category, value);
									});
                                }
                            } else {
                                var personnel = '<div class="nodatas">' +
                                    '<img src="/static/web/images/nodata.png"/>' +
                                    '<p>抱歉，找不到相关数据</p></div>';

                                $(".serviceArea").eq(0).html(personnel);
                            }
                        } else {
							$('.sortType').eq(2).attr('style','display:blcok;');
                            var res = /^[0-9]+$/;
                            $('.num').html(msg.data.count);
                            $('.currentPage').html(page);
                            var pages = Math.ceil(msg.data.count / 20);
                            $('.allPage').html(pages);
                            $(".count").html(msg.data.count);
                            //商品
                            if (msg.data.service.length != 0) {
                                var service = "";//商品
                                for (var e = 0; e < msg.data.service.length; e++) {
									var storeName = cut(msg.data.service[e].username,18);
                                    var price_num = number_format(msg.data.service[e].store, 2, ".", ",");
                                    // if (i == 4 || i == 9 || i == 14 || i == 19) {
                                    if (res.test((e + 1) / 5)) {
                                        service += '<div class="serviceItem mr0">';
                                    } else {
                                        service += '<div class="serviceItem">';
                                    }
                                    service += '<a class="goDetails" href="/index.php/index' +
                                        '/service/service_details.html?id=' + msg.data.service[e].id + '">' +
                                        '<img src="/Images/serviceGoods/' + msg.data.service[e].image + '"/></a>' +
                                        '<div class="serviceCon"><span class="prices">￥' + price_num + '</span>' +
                                        '<a class="serviceTitle moreline" limit="24" href="/index.php/index' +
                                        '/service/service_details.html?id=' + msg.data.service[e].id + '">' + storeName + '</a>' +
                                        '<a class="company text_overflow" href="store_details.html" ' +
                                        'title="' + msg.data.service[e].name + '">' + msg.data.service[e].name + '</a>' +
                                        '<p class="volume">成交量<span class="volumeNum">' + msg.data.service[e].value + '</span>笔</p>' +
                                        '<p class="assess">评价<span class="assessNum">' + msg.data.service[e].rate + '</span>条</p></div></div>';
                                }

                                $(".serviceArea").eq(1).html(service);
                                if (msg.data.service.length == 0) {
                                    $('.page').eq(1).html('');
                                } else {
                                    $('.page').eq(1).html(msg.data.render);
                                    $(".pagination").eq(1).delegate("a", "click", function () {
                                        var index = $("#index").val();
                                        var num = $(this).attr("num");
                                        var value = $("#value").val();
                                        if (num) {
                                            postfile(num, index, value);
                                        }
                                    });
									$("#GO").on('click',function(){
										var king = $("#go").val();
										if(king > pages){
											layer.alert("最多输入"+pages+"页");
											return;
										}
										postfile(king, index, value);
									});
                                }
                            } else {
                                var personne = '<div class="nodatas">' +
                                    '<img src="/static/web/images/nodata.png"/>' +
                                    '<p>抱歉，找不到相关数据</p></div>';

                                $(".serviceArea").eq(1).html(personne);
                            }
                        }

                    } else {
                        layer.msg('查询失败!', {icon: 1, time: 1000});
                    }
                }
            })
        } else {
            window.location.href = "{:url('index/login/index')}";
        }
    }

    /**推荐服务*/
    function get_view() {
        $.ajax({
            type: "get",
            url: "{:url('api/service/rand_goods')}",
            data: {'number': 2, 'order': 'rand()'},
            dataType: 'jsonp',
            success: function (msg) {
                var html = "";
                if (msg.code == 200) {
                    for (var i = 0; i < msg.data.length; i++) {
						var price_num = number_format(msg.data[i].price, 2, ".", ",");
                        html += '<div class="items"><a class="links" href="/index.php/index/service/service_details.html?id=' + msg.data[i].id + '">';
                        html += '<img src="/Images/serviceGoods/' + msg.data[i].pic + '" alt="' + msg.data[i].goods_name + '" /></a>';
                        html += '<div class="borderLine">';
                        html += '<span class="prices">￥' + price_num + '</span>';
                        html += '<a class="itemsTitle text_overflow" href="service_details.html?id=' + msg.data[i].id + '" title="' + msg.data[i].goods_name + '"></a>' + msg.data[i].goods_name + '</div></div>';
                    }
                    $('.recommendCon').eq(1).html(html);
                }
            }
        });
    }


    $('.icon-refresh').eq(0).on('click', function () {
        hot_view();
    });

    $('.icon-refresh').eq(1).on('click', function () {
        get_view();
    });

    /**推荐交易服务**/
    function hot_view() {
        $.ajax({
            type: "get",
            url: "{:url('api/trading/trading_rand')}",
            data: {'number': 2, 'order': 'rand()'},
            dataType: 'jsonp',
            success: function (msg) {
                var html = "";
                if (msg.code == 200) {
                    for (var i = 0; i < msg.data.length; i++) {
						var price_num = number_format(msg.data[i].store, 2, ".", ",");
                        html += '<div class="items">' +
                            '<a class="links" href="/index.php/index/trade/trade_details.html?id=' + msg.data[i].id + '">' +
                            '<img src="/Images/tradingMarket/' + msg.data[i].image + '"' +
                            ' alt="' + msg.data[i].username + '"/></a><div class="borderLine">' +
                            '<span class="prices">￥' + price_num + '起</span>' +
                            '<a class="itemsTitle text_overflow" href="trade_details.html?id=' + msg.data[i].id + '"' +
                            ' title="' + msg.data[i].username + '">' + msg.data[i].username + '</a></div></div>';
                    }
                    $('.recommendCon').eq(0).html(html);
                }
            }
        });
    }


</script>
{/block}